(display "\n========================================\n")
(define (accumulate op initial sequence)
    (if (null? sequence)
        initial
        (op (car sequence)
            (accumulate op initial (cdr sequence)))))

(define (map p sequence)
    (accumulate (lambda (x y)
                    (cons (p x) y))
                ()
                sequence))

(display (map square (list 1 2 3 4)))
(newline)

(define (append seq1 seq2)
    (accumulate cons seq2 seq1))

(display (append (list 1 2 3 (list 0 0 0)) (list 4 5 6 (list 7 8 9))))
(newline)

(define (length sequence)
    (if (null? sequence)
        0
        (+ (length (cdr sequence)) 1)))

(define (length sequence)
    (accumulate (lambda (x y) (+ 1 y)) 0 sequence))


(display (length (list 1 2 3 4 5 6)))

(display "\n========================================\n")
